package besta.moon.statement;

import java.sql.*;
import java.math.*;
import java.util.Map;
import java.util.Calendar;
import java.net.URL;
import java.io.*;

import besta.moon.MoonException;
import besta.moon.MoonConnection;
import besta.moon.MoonCode;
import besta.moon.sql.Expression;
import besta.moon.sql.datatype.DateTime;
import besta.moon.sql.datatype.MutableNumeric;

public class MoonCallableStatement extends MoonPreparedStatement implements CallableStatement {

    private boolean wasNull;

    public MoonCallableStatement(MoonConnection con, String sql) throws SQLException {
        super(con, sql);
    }

    public MoonCallableStatement(MoonConnection con, String sql, int rsType, int rsConcurrency) throws SQLException {
        super(con, sql, rsType, rsConcurrency);
    }

    private Expression getValue(int i) throws SQLException {

        throw new java.lang.UnsupportedOperationException("Method getValue() not yet implemented.");
    }

    private int findParameter(String parameterName) {

        throw new java.lang.UnsupportedOperationException("Method findParameter() not yet implemented.");
    }

    @Override
    public void registerOutParameter(int i, int sqlType) throws SQLException {

        throw new java.lang.UnsupportedOperationException("Method registerOutParameter() not yet implemented.");
    }

    @Override
    public void registerOutParameter(int i, int sqlType, int scale) throws SQLException {

        throw new java.lang.UnsupportedOperationException("Method registerOutParameter() not yet implemented.");
    }

    @Override
    public boolean wasNull() {
        return wasNull;
    }

    @Override
    public String getString(int i) throws SQLException {
        try {
            String obj = getValue(i).getString();
            wasNull = obj == null;
            return obj;
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public boolean getBoolean(int i) throws SQLException {
        try {
            Expression expr = getValue(i);
            wasNull = expr.isNull();
            return expr.getBoolean();
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public byte getByte(int i) throws SQLException {
        return (byte) getInt(i);
    }

    @Override
    public short getShort(int i) throws SQLException {
        return (byte) getInt(i);
    }

    @Override
    public int getInt(int i) throws SQLException {
        try {
            Expression expr = getValue(i);
            wasNull = expr.isNull();
            return expr.getInt();
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public long getLong(int i) throws SQLException {
        try {
            Expression expr = getValue(i);
            wasNull = expr.isNull();
            return expr.getLong();
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public float getFloat(int i) throws SQLException {
        try {
            Expression expr = getValue(i);
            wasNull = expr.isNull();
            return expr.getFloat();
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public double getDouble(int i) throws SQLException {
        try {
            Expression expr = getValue(i);
            wasNull = expr.isNull();
            return expr.getLong();
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public BigDecimal getBigDecimal(int i, int scale) throws SQLException {
        try {
            MutableNumeric obj = getValue(i).getNumeric();
            wasNull = obj == null;
            if (wasNull) {
                return null;
            }
            return obj.toBigDecimal(scale);
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public byte[] getBytes(int i) throws SQLException {
        try {
            byte[] obj = getValue(i).getBytes();
            wasNull = obj == null;
            return obj;
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public Date getDate(int i) throws SQLException {
        try {
            Expression expr = getValue(i);
            wasNull = expr.isNull();
            if (wasNull) {
                return null;
            }
            return DateTime.getDate(expr.getLong());
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public Time getTime(int i) throws SQLException {
        try {
            Expression expr = getValue(i);
            wasNull = expr.isNull();
            if (wasNull) {
                return null;
            }
            return DateTime.getTime(expr.getLong());
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public Timestamp getTimestamp(int i) throws SQLException {
        try {
            Expression expr = getValue(i);
            wasNull = expr.isNull();
            if (wasNull) {
                return null;
            }
            return DateTime.getTimestamp(expr.getLong());
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public Object getObject(int i) throws SQLException {
        try {
            Object obj = getValue(i).getObject();
            wasNull = obj == null;
            return obj;
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public BigDecimal getBigDecimal(int i) throws SQLException {
        try {
            MutableNumeric obj = getValue(i).getNumeric();
            wasNull = obj == null;
            if (wasNull) {
                return null;
            }
            return obj.toBigDecimal();
        } catch (Exception e) {
            throw MoonException.createFromException(e);
        }
    }

    @Override
    public Object getObject(int i, Map map) throws SQLException {

        throw MoonException.create(MoonCode.UNSUPPORTED_OPERATION, "Method getObject() not yet implemented.");
    }

    @Override
    public Ref getRef(int i) throws SQLException {

        throw MoonException.create(MoonCode.UNSUPPORTED_OPERATION, "Method getRef() not yet implemented.");
    }

    @Override
    public Blob getBlob(int i) throws SQLException {

        throw MoonException.create(MoonCode.UNSUPPORTED_OPERATION, "Method getBlob() not yet implemented.");
    }

    @Override
    public Clob getClob(int i) throws SQLException {

        throw MoonException.create(MoonCode.UNSUPPORTED_OPERATION, "Method getClob() not yet implemented.");
    }

    @Override
    public Array getArray(int i) throws SQLException {
        throw MoonException.create(MoonCode.UNSUPPORTED_OPERATION, "Method getArray() not yet implemented.");
    }

    @Override
    public Date getDate(int i, Calendar cal) throws SQLException {

        throw MoonException.create(MoonCode.UNSUPPORTED_OPERATION, "Method getDate() not yet implemented.");
    }

    @Override
    public Time getTime(int i, Calendar cal) throws SQLException {

        throw MoonException.create(MoonCode.UNSUPPORTED_OPERATION, "Method getTime() not yet implemented.");
    }

    @Override
    public Timestamp getTimestamp(int i, Calendar cal) throws SQLException {

        throw MoonException.create(MoonCode.UNSUPPORTED_OPERATION, "Method getTimestamp() not yet implemented.");
    }

    @Override
    public void registerOutParameter(int i, int sqlType, String typeName) throws SQLException {

        throw MoonException.create(MoonCode.UNSUPPORTED_OPERATION,
                "Method registerOutParameter() not yet implemented.");
    }

    @Override
    public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
        registerOutParameter(findParameter(parameterName), sqlType);
    }

    @Override
    public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
        registerOutParameter(findParameter(parameterName), sqlType, scale);
    }

    @Override
    public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
        registerOutParameter(findParameter(parameterName), sqlType, typeName);
    }

    @Override
    public URL getURL(int parameterIndex) throws SQLException {

        throw MoonException.create(MoonCode.UNSUPPORTED_OPERATION, "Method getURL() not yet implemented.");
    }

    @Override
    public void setURL(String parameterName, URL x) throws SQLException {
        setURL(findParameter(parameterName), x);
    }

    @Override
    public void setNull(String parameterName, int sqlType) throws SQLException {
        setNull(findParameter(parameterName), sqlType);
    }

    @Override
    public void setBoolean(String parameterName, boolean x) throws SQLException {
        setBoolean(findParameter(parameterName), x);
    }

    @Override
    public void setByte(String parameterName, byte x) throws SQLException {
        setByte(findParameter(parameterName), x);
    }

    @Override
    public void setShort(String parameterName, short x) throws SQLException {
        setShort(findParameter(parameterName), x);
    }

    @Override
    public void setInt(String parameterName, int x) throws SQLException {
        setInt(findParameter(parameterName), x);
    }

    @Override
    public void setLong(String parameterName, long x) throws SQLException {
        setLong(findParameter(parameterName), x);
    }

    @Override
    public void setFloat(String parameterName, float x) throws SQLException {
        setFloat(findParameter(parameterName), x);
    }

    @Override
    public void setDouble(String parameterName, double x) throws SQLException {
        setDouble(findParameter(parameterName), x);
    }

    @Override
    public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
        setBigDecimal(findParameter(parameterName), x);
    }

    @Override
    public void setString(String parameterName, String x) throws SQLException {
        setString(findParameter(parameterName), x);
    }

    @Override
    public void setBytes(String parameterName, byte[] x) throws SQLException {
        setBytes(findParameter(parameterName), x);
    }

    @Override
    public void setDate(String parameterName, Date x) throws SQLException {
        setDate(findParameter(parameterName), x);
    }

    @Override
    public void setTime(String parameterName, Time x) throws SQLException {
        setTime(findParameter(parameterName), x);
    }

    @Override
    public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
        setTimestamp(findParameter(parameterName), x);
    }

    @Override
    public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
        setAsciiStream(findParameter(parameterName), x, length);
    }

    @Override
    public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
        setBinaryStream(findParameter(parameterName), x, length);
    }

    @Override
    public void setObject(String parameterName, Object x, int sqlType, int scale) throws SQLException {
        setObject(findParameter(parameterName), x, sqlType, scale);
    }

    @Override
    public void setObject(String parameterName, Object x, int sqlType) throws SQLException {
        setObject(findParameter(parameterName), x, sqlType);
    }

    @Override
    public void setObject(String parameterName, Object x) throws SQLException {
        setObject(findParameter(parameterName), x);
    }

    @Override
    public void setCharacterStream(String parameterName, Reader x, int length) throws SQLException {
        setCharacterStream(findParameter(parameterName), x, length);
    }

    @Override
    public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
        setDate(findParameter(parameterName), x, cal);
    }

    @Override
    public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
        setTime(findParameter(parameterName), x, cal);
    }

    @Override
    public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
        setTimestamp(findParameter(parameterName), x, cal);
    }

    @Override
    public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
        setNull(findParameter(parameterName), sqlType, typeName);
    }

    @Override
    public String getString(String parameterName) throws SQLException {
        return getString(findParameter(parameterName));
    }

    @Override
    public boolean getBoolean(String parameterName) throws SQLException {
        return getBoolean(findParameter(parameterName));
    }

    @Override
    public byte getByte(String parameterName) throws SQLException {
        return getByte(findParameter(parameterName));
    }

    @Override
    public short getShort(String parameterName) throws SQLException {
        return getShort(findParameter(parameterName));
    }

    @Override
    public int getInt(String parameterName) throws SQLException {
        return getInt(findParameter(parameterName));
    }

    @Override
    public long getLong(String parameterName) throws SQLException {
        return getLong(findParameter(parameterName));
    }

    @Override
    public float getFloat(String parameterName) throws SQLException {
        return getFloat(findParameter(parameterName));
    }

    @Override
    public double getDouble(String parameterName) throws SQLException {
        return getDouble(findParameter(parameterName));
    }

    @Override
    public byte[] getBytes(String parameterName) throws SQLException {
        return getBytes(findParameter(parameterName));
    }

    @Override
    public Date getDate(String parameterName) throws SQLException {
        return getDate(findParameter(parameterName));
    }

    @Override
    public Time getTime(String parameterName) throws SQLException {
        return getTime(findParameter(parameterName));
    }

    @Override
    public Timestamp getTimestamp(String parameterName) throws SQLException {
        return getTimestamp(findParameter(parameterName));
    }

    @Override
    public Object getObject(String parameterName) throws SQLException {
        return getObject(findParameter(parameterName));
    }

    @Override
    public BigDecimal getBigDecimal(String parameterName) throws SQLException {
        return getBigDecimal(findParameter(parameterName));
    }

    @Override
    public Object getObject(String parameterName, Map map) throws SQLException {
        return getObject(findParameter(parameterName), map);
    }

    @Override
    public Ref getRef(String parameterName) throws SQLException {
        return getRef(findParameter(parameterName));
    }

    @Override
    public Blob getBlob(String parameterName) throws SQLException {
        return getBlob(findParameter(parameterName));
    }

    @Override
    public Clob getClob(String parameterName) throws SQLException {
        return getClob(findParameter(parameterName));
    }

    @Override
    public Array getArray(String parameterName) throws SQLException {
        return getArray(findParameter(parameterName));
    }

    @Override
    public Date getDate(String parameterName, Calendar cal) throws SQLException {
        return getDate(findParameter(parameterName), cal);
    }

    @Override
    public Time getTime(String parameterName, Calendar cal) throws SQLException {
        return getTime(findParameter(parameterName), cal);
    }

    @Override
    public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
        return getTimestamp(findParameter(parameterName), cal);
    }

    @Override
    public URL getURL(String parameterName) throws SQLException {
        return getURL(findParameter(parameterName));
    }

    @Override
    public void setRowId(int parameterIndex, RowId x) throws SQLException {

    }

    @Override
    public void setNString(int parameterIndex, String value) throws SQLException {

    }

    @Override
    public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {

    }

    @Override
    public void setNClob(int parameterIndex, NClob value) throws SQLException {

    }

    @Override
    public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {

    }

    @Override
    public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {

    }

    @Override
    public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {

    }

    @Override
    public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {

    }

    @Override
    public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {

    }

    @Override
    public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {

    }

    @Override
    public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {

    }

    @Override
    public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {

    }

    @Override
    public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {

    }

    @Override
    public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {

    }

    @Override
    public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {

    }

    @Override
    public void setClob(int parameterIndex, Reader reader) throws SQLException {

    }

    @Override
    public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {

    }

    @Override
    public void setNClob(int parameterIndex, Reader reader) throws SQLException {

    }

    @Override
    public boolean isClosed() throws SQLException {

        return false;
    }

    @Override
    public void setPoolable(boolean poolable) throws SQLException {

    }

    @Override
    public boolean isPoolable() throws SQLException {

        return false;
    }

    @Override
    public void closeOnCompletion() throws SQLException {

    }

    @Override
    public boolean isCloseOnCompletion() throws SQLException {

        return false;
    }

    @Override
    public <T> T unwrap(Class<T> iface) throws SQLException {

        return null;
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {

        return false;
    }

    @Override
    public RowId getRowId(int parameterIndex) throws SQLException {

        return null;
    }

    @Override
    public RowId getRowId(String parameterName) throws SQLException {

        return null;
    }

    @Override
    public void setRowId(String parameterName, RowId x) throws SQLException {

    }

    @Override
    public void setNString(String parameterName, String value) throws SQLException {

    }

    @Override
    public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {

    }

    @Override
    public void setNClob(String parameterName, NClob value) throws SQLException {

    }

    @Override
    public void setClob(String parameterName, Reader reader, long length) throws SQLException {

    }

    @Override
    public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {

    }

    @Override
    public void setNClob(String parameterName, Reader reader, long length) throws SQLException {

    }

    @Override
    public NClob getNClob(int parameterIndex) throws SQLException {

        return null;
    }

    @Override
    public NClob getNClob(String parameterName) throws SQLException {

        return null;
    }

    @Override
    public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {

    }

    @Override
    public SQLXML getSQLXML(int parameterIndex) throws SQLException {

        return null;
    }

    @Override
    public SQLXML getSQLXML(String parameterName) throws SQLException {

        return null;
    }

    @Override
    public String getNString(int parameterIndex) throws SQLException {

        return null;
    }

    @Override
    public String getNString(String parameterName) throws SQLException {

        return null;
    }

    @Override
    public Reader getNCharacterStream(int parameterIndex) throws SQLException {

        return null;
    }

    @Override
    public Reader getNCharacterStream(String parameterName) throws SQLException {

        return null;
    }

    @Override
    public Reader getCharacterStream(int parameterIndex) throws SQLException {

        return null;
    }

    @Override
    public Reader getCharacterStream(String parameterName) throws SQLException {

        return null;
    }

    @Override
    public void setBlob(String parameterName, Blob x) throws SQLException {

    }

    @Override
    public void setClob(String parameterName, Clob x) throws SQLException {

    }

    @Override
    public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {

    }

    @Override
    public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException {

    }

    @Override
    public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {

    }

    @Override
    public void setAsciiStream(String parameterName, InputStream x) throws SQLException {

    }

    @Override
    public void setBinaryStream(String parameterName, InputStream x) throws SQLException {

    }

    @Override
    public void setCharacterStream(String parameterName, Reader reader) throws SQLException {

    }

    @Override
    public void setNCharacterStream(String parameterName, Reader value) throws SQLException {

    }

    @Override
    public void setClob(String parameterName, Reader reader) throws SQLException {

    }

    @Override
    public void setBlob(String parameterName, InputStream inputStream) throws SQLException {

    }

    @Override
    public void setNClob(String parameterName, Reader reader) throws SQLException {

    }

    @Override
    public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException {

        return null;
    }

    @Override
    public <T> T getObject(String parameterName, Class<T> type) throws SQLException {

        return null;
    }

}
